import { Component, OnInit } from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd/message';
import {Service} from '../service/service';
import {Router} from '@angular/router';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
  isOkLoading = false;
  passwordVisible = false;
  password: string;
  username: string;
  constructor(public msg: NzMessageService, public service: Service, private router: Router) { }

  ngOnInit(): void {
  }

  login(): void {
    this.isOkLoading = true;
    const data = {
      username: this.username,
      password: this.password
    };
    console.log(data);
    console.log(this.service)
    this.service.login(data, (result) => {
      console.log(result);
      this.isOkLoading = false;
      if (result.status == 1){
        this.msg.info('登录成功');
        localStorage.setItem('token', result.token);
        this.router.navigate(['layout']);
      }else{
        this.msg.error('登录失败');
      }
    });
  }

}
